package com.hdu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hdu.entity.Chat;
import com.hdu.pojo.Friend;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 聊天记录实体类 Mapper 接口
 * </p>
 *
 * @author xiaobai
 * @since 2024-05-20
 */
public interface ChatMapper extends BaseMapper<Chat> {

    /**
     * 班级列表查询
     *
     * @return List<Friend>
     */
    @Select("select cID as id, concat('高20', left(cID, 2), '届', trim(leading '0' FROM right(cID, 2)), '班') as username, avatar,0 as type from class where cID in (select cID from class_storage s where s.tID=#{tID})")
    List<Friend> classList(String tID);

    @Select("select id,nickname,avatar,1 as type from account where id in(select tID from class_storage where cID=#{cID} and tID!=#{tID})")
    List<Friend> teacherList(String cID,String tID);

    @Select("select id,nickname,avatar,2 as type from account where id in(select sID from student where cID=#{cID})")
    List<Friend> studentList(String cID);

    List<Chat> selectChat(Chat chat);

    @Insert("insert into chat(id, sender, content, type, ip_address, ip_source) values (#{id},#{sender},#{content},#{type},#{ipAddress},#{ipSource})")
    int insert(Chat chat);

    @Delete("delete from chat where id=#{id}")
    void deleteById(String id);
}
